package com.hsy.linemoney.modules.common;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;

import com.deparse.dpframe.tools.utils.DPLogUtil;
import com.deparse.dpframe.ui.android.app.activity.DPBaseActivityWithSimpleActionBar;
import com.hsy.linemoney.R;
import com.hsy.linemoney.apiservice.LineMoneyContext;
import com.hsy.linemoney.common.LoadingProgressDialog;
import com.hsy.linemoney.modules.auth.activity.LoginActivity;
import com.hsy.linemoney.utils.CommonUtils;

/**
 * Created by Administrator on 2016/6/23.
 */
public class CommonBaseActivityWithSimpleActionBar extends DPBaseActivityWithSimpleActionBar {
    public int densityDpi;// 屏幕密度，单位为dpi

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hideProgressDialog();

        if (!LineMoneyContext.isLocalSetted()) {
            startActivityForResult(LocalSetActivity.class, 0);
        }

        if (!LineMoneyContext.isLoggedIn()) {
            DPLogUtil.d("!LineMoneyContext.isLoggedIn()");
//            startActivityWithTaskCleared(LoginActivity.class);
        }

        LineMoneyContext.changeLocalLanguage(LineMoneyContext.getLocalLanguagePair());

        setStausBarBackgroundColor(getResources().getColor(R.color.color_action_bar_bg));

        int color = getResources().getColor(R.color.color_action_bar_bg);
        setActionBarBackgroundColor(color);

        DisplayMetrics dm = new DisplayMetrics();
        this.getWindowManager().getDefaultDisplay().getMetrics(dm);
//        screenWidth = dm.widthPixels;
//        screenHeight = dm.heightPixels;
//        densityDpi = dm.densityDpi;
//        scale = dm.density;
//        fontScale = dm.scaledDensity;
    }

    @Override
    protected void onStop() {
        super.onStop();
        hideProgressDialog();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        hideProgressDialog();
    }

    protected boolean shouldCancelProgressDialog() {
        return true;
    }

    private LoadingProgressDialog loadingProgressDialog;

    protected void showProgressDialog(Activity activity) {
        hideProgressDialog();
        loadingProgressDialog = new LoadingProgressDialog(activity);
        loadingProgressDialog.show();
    }

    protected void hideProgressDialog() {
        if (null != loadingProgressDialog) {
            loadingProgressDialog.dismiss();
            loadingProgressDialog = null;
        }
    }
}
